<?php
namespace app\common\model;
class MallConfig extends Base
{
    protected function initialize()
    {
        parent::initialize();
    }

    public static function saveConfig($mall_id,$data) {
        $allow = [
            'share_title','share_picture','share_desc',
            'shop_name','shop_open','shop_close_reason','shop_tel','shop_advert','shop_ad_picture','shop_ad_video','shop_qrcode',
            'credit_money','credit_score','credit_cash',
            'wechat_mchid','wechat_mchkey',//微信商户号和秘钥
            'wechat_mchkeypem','wechat_mchcertpem',//商户证书文件绝对路径
            'chat_manager','chat_forbidden','chat_type',//聊天室的管理员 禁言 群聊模式
            'open_qrcode','open_mobile','chat_view',
            'redbag_type',   //抢红包存储设置
            'dikou_rate', //抵扣金比例，默认设置1:10
            'chat_announce', //聊天公告
            'live_manager',//直播管理员
            'chat_bg_picture', //聊天室背景图片
        ];
        //$data['chat_view'] = $data['chat_view']?$data['chat_view']:0;//默认群人气
        foreach($data as $k=>$v) {
            if(!in_array($k,$allow)) {
                continue;
            }
            $where = [
                'name' => $k,
                'mall_id' => $mall_id
            ];
            $old = self::getOne($where);
            if($old) {
                self::where($where)->update([
                    'value' => $v
                ]);
            }else{
                self::create([
                    'mall_id' => $mall_id,
                    'name' => $k,
                    'value' => $v
                ]);
            }
        }
    }

    public static function  getConfig ($mall_id) {
        $where = [
            'mall_id' => $mall_id
        ];
        return self::where($where)->column('name,value');
    }
}